package com.ltxtiyu.video.cacheDaoImpl;

import com.ltxtiyu.video.cacheDao.ConfigCacheDao;
import com.ltxtiyu.video.dao.ltx.ConfigDao;
import com.ltxtiyu.video.entity.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "ltx:config")
public class ConfigCacheDaoImpl implements ConfigCacheDao {

    @Autowired
    ConfigDao configDao;

    @Override
    @CacheEvict(key = "#p0")
    public void deleteByPrimaryKey(String ckey) {
        Config config = configDao.selectByCkey(ckey);
        if(config != null){
            configDao.deleteByPrimaryKey(config.getId());
        }
    }

    @Override
    @CachePut( key = "#record.ckey",unless="#result == null")
    public Config insertSelective(Config record) {
        configDao.insertSelective(record);
        return record;
    }

    @Override
    @CachePut(key = "#record.ckey",unless="#result == null")
    public Config updateByCkey(Config record) {
        configDao.updateByCkey(record);
        return record;
    }

    @Override
    @Cacheable(key = "#p0",unless="#result == null")
    public Config selectByCkey(String ckey) {
        return configDao.selectByCkey(ckey);
    }
}
